package com.haoan.index.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.haoan.common.annotation.Anonymous;
import com.haoan.index.domain.CulturalRelic;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.haoan.common.annotation.Log;
import com.haoan.common.core.controller.BaseController;
import com.haoan.common.core.domain.AjaxResult;
import com.haoan.common.enums.BusinessType;
import com.haoan.index.domain.Food;
import com.haoan.index.service.FoodService;
import com.haoan.common.utils.poi.ExcelUtil;
import com.haoan.common.core.page.TableDataInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 美食Controller
 *
 * @author autoGen
 * @date 2025-02-21
 */
@Api(value="美食",tags = "美食")
@RestController
@RequestMapping("/index/food")
public class FoodController extends BaseController
{
    @Resource
    private FoodService foodService;

    /**
     * 点赞
     */
    @ApiOperation("点赞")
    @Anonymous
    @GetMapping(value = "thumbsUp/{id}")
    public AjaxResult thumbsUp(@PathVariable("id") Long id)
    {
        Food food = foodService.selectFoodById(id);
        food.setLikes(food.getLikes()+1L);
        foodService.updateFood(food);
        return success(food);
    }

    /**
     * 查询美食列表
     */
    @ApiOperation("查询美食列表")
    @GetMapping("/list")
    @Anonymous
    public TableDataInfo list(Food food)
    {
        startPage();
        List<Food> list = foodService.selectFoodList(food);
        return getDataTable(list);
    }

    /**
     * 导出美食列表
     */
    @ApiOperation("导出美食列表")
    @PreAuthorize("@ss.hasPermi('index:food:export')")
    @Log(title = "美食", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Food food)
    {
        List<Food> list = foodService.selectFoodList(food);
        ExcelUtil<Food> util = new ExcelUtil<Food>(Food.class);
        util.exportExcel(response, list, "美食数据");
    }

    /**
     * 获取美食详细信息
     */
    @ApiOperation("获取美食详细信息")
    @GetMapping(value = "/{id}")
    @Anonymous
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(foodService.selectFoodById(id));
    }

    /**
     * 新增美食
     */
    @ApiOperation("新增美食")
    @PreAuthorize("@ss.hasPermi('index:food:add')")
    @Log(title = "美食", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Food food)
    {
        return toAjax(foodService.insertFood(food));
    }

    /**
     * 修改美食
     */
    @ApiOperation("修改美食")
    @PreAuthorize("@ss.hasPermi('index:food:edit')")
    @Log(title = "美食", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Food food)
    {
        return toAjax(foodService.updateFood(food));
    }

    /**
     * 删除美食
     */
    @ApiOperation("删除美食")
    @PreAuthorize("@ss.hasPermi('index:food:remove')")
    @Log(title = "美食", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(foodService.deleteFoodByIds(ids));
    }
}
